<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">设置</view>
    </view>
    <view class="tophr"></view>

    <view class="ubs">
      <view class="ub" @tap="user_select2">
        <view class="ub_l">修改密码</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t"
          >{{ user.corp_name
          }}<image
            src="../../static/img/user/ic_certificate.png"
            class="ub_rz"
            v-if="user.corp_id"
          ></image
        ></view>
      </view>
    </view>

    <view class="ubs">
      <view class="ub" @tap="user_set_msg">
        <view class="ub_l">新消息通知</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
      </view>
      <view class="ub" @tap="user_set_pr">
        <view class="ub_l">隐私</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
      </view>
    </view>

    <view class="ubs">
      <view class="ub" @tap="user_help">
        <view class="ub_l">帮助中心</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
      </view>
      <view class="ub" @tap="user_about">
        <view class="ub_l">关于墨斗</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
      </view>
    </view>

    <view class="ubs">
      <view class="ub" @tap="user_select">
        <view class="ub_l">我的企业</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t"
          >{{ user.corp_name
          }}<image
            src="../../static/img/user/ic_certificate.png"
            class="ub_rz"
            v-if="user.corp_id"
          ></image
        ></view>
      </view>
    </view>

    <view class="ubs ubscc" @tap="bindLogin">
      退出登录
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['hasLogin', 'forcedLogin']),
  },

  data() {
    return {
      user: {},
    };
  },
  onShow() {
    // 获取用户信息
    request({
      url: '/ucenter/user',
      method: 'GET',

      success: res => {
        if (res.data.success == true) {
          console.log('用户信息1：', res.data.data);
          uni.setStorageSync('user', res.data.data);
          this.user = res.data.data;
          console.log('sdf', this.user.avatar);
          if (!this.user.avatar || this.user.avatar == '') {
            this.user.avatar = '../../static/img/Default_avatar.png';
          }
        } else {
          uni.navigateTo({
            url: '../login/login',
          });
          console.log('qqqqqqqqq222222');
          return false;
        }
      },
    });
  },
  methods: {
    ...mapMutations(['logout']),
    // 跳转
    user_set_msg() {
      uni.navigateTo({
        url: '../user/user_set_msg',
      });
    },
    user_set_pr() {
      uni.navigateTo({
        url: '../user/user_set_pr',
      });
    },
    user_help() {
      uni.navigateTo({
        url: '../user/user_help',
      });
    },
    user_about() {
      uni.navigateTo({
        url: '../user/user_about',
      });
    },
    user_select() {
      uni.navigateTo({
        url: '../user/user_select',
      });
    },
    user_select2() {
      uni.navigateTo({
        url: '../pwd/pwdthree',
      });
    },

    bindLogin() {
      uni.removeStorageSync('user_id');
      uni.removeStorageSync('refresh_token');
      uni.removeStorageSync('expires_in');
      uni.removeStorageSync('access_token');
      uni.removeStorageSync('token_type');

      uni.removeStorageSync('user');

      uni.removeStorageSync('xt');
      uni.removeStorageSync('dqfull_name');
      uni.removeStorageSync('week');
      uni.removeStorageSync('rq');
      uni.removeStorageSync('jenterprise');
      uni.removeStorageSync('jqeditry');
      uni.removeStorageSync('jqeditrytx');
      uni.removeStorageSync('ys');

      uni.removeStorageSync('jt');
      uni.removeStorageSync('jc');

      uni.removeStorageSync('dqxm');
      uni.removeStorageSync('jkcs');
      uni.removeStorageSync('osscs');
      uni.removeStorageSync('lsxg');

      uni.removeStorageSync('temp_data');
      uni.removeStorageSync('xzrytx');
      uni.removeStorageSync('qy');
      uni.removeStorageSync('xzry');
      uni.removeStorageSync('lslb');
      uni.removeStorageSync('qylstx');
      uni.removeStorageSync('temp_data3');
      uni.removeStorageSync('lslb3');
      uni.removeStorageSync('xt');

      uni.navigateTo({
        url: '../login/login',
      });
    },
    bindLogout() {
      this.logout();
      /**
       * 如果需要强制登录跳转回登录页面
       */
      if (this.forcedLogin) {
        uni.reLaunch({
          url: '../login/login',
        });
      }
    },
    navigateBack() {
      // uni.navigateTo({
      // 	url: '../user/user',
      // });
      uni.switchTab({
        url: '/pages/user/user',
      });
      // uni.navigateBack()
    },
  },
};
</script>

<style>
.ubs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 20rpx 0 0 0;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.ub {
  width: 720rpx;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  border-bottom: 1px solid #dddddd;
}
.ubs .ub:last-child {
  border: 0;
}
.ub_l {
  width: auto;
  height: auto;
  display: block;
  float: left;
  font-size: 34rpx;
  line-height: 90rpx;
  color: #000000;
  margin: 0rpx 0 0 0;
}
.ub_jt {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 0 0;
}
.ub_t {
  width: auto;
  height: 40rpx;
  display: block;
  float: right;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: right;
  color: #999999;
  margin: 25rpx 20rpx 0 0;
}
.ub_t image {
  width: 36rpx;
  height: 36rpx;
  display: block;
  float: right;
  margin: 0rpx 0rpx 0 6rpx;
}
.ub_tx {
  width: 114rpx;
  height: 114rpx;
  display: block;
  float: right;
  margin: 30rpx 20rpx 30rpx 0;
  border-radius: 8rpx;
}
.uba {
  height: auto;
}
.uba .ub_l {
  margin-top: 45rpx;
}
.uba .ub_jt {
  margin-top: 75rpx;
}
.ubscc {
  text-align: center;
  line-height: 90rpx;
  color: #eb5342;
  font-size: 32rpx;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.tophr {
  width: 100%;
  height: 88rpx;
}
</style>
